# 1.有7个整数，其中有3个数出现了两次，1个数出现了一次， 找出出现了一次的那个数
def num_1time_search(nums):
    result = 0
    for x in nums:
        result ^= x
    print(result)


nums = [1, 1, 0, 0, 2, 2, 5]
num_1time_search(nums)


# 2.从1打印到20，横着打为1排
def use_for_print():
    print(*range(21))
    for x in range(21):
        print(f'{x}', end=' ')
    print()
    for x in range(21):
        print(x, end=' ')


use_for_print()
print()


# 3.写一个say_hello函数打印多次hello并给该函数加备注（具体打印几次依靠传递的参数）
# 然后调用say_hello，同时学会快速查看函数备注，及如何跳转到函数实现快捷操作（与上课一致）
def say_hello(times):
    """
    打印指定次数的say_hello
    :param times:次数
    :return:
    """
    print("say_hello" * times)


say_hello(int(input("打印次数")))

# 5.列表、元组，字典的各种操作
# 列表的增删查改
stu_list = ["zhangsan", "11", "lisi", 15, "wangwu", "22", 15, "22"]
num_list = [55, 55, 55, 48, 26, 45, 12, 8, 76, 4, 23, 39, 10]

print(stu_list.count("22"))
print(num_list.count(55))

print(f'id(stu_list) = {id(stu_list)}')  # stu_list的内存位置
print(f'id(num_list) = {id(num_list)}')  # num_list的内存位置

# 查
print(stu_list[4])
print(num_list[6])
print(stu_list.index("lisi"))
print(num_list.index(4))

# 增 & 改
print('*' * 50)
stu_list[0] = "张三"  # 修改
stu_list.append("李四")  # 尾部添加
stu_list.insert(5, "王五")  # 指定插入
stu_list.extend(num_list)  # 尾部列表合并
print(f'stu_list = {stu_list}')
print(f'numlist={num_list}')
num_list.sort()  # 排序
print(f'num_list = {num_list}')
num_list.sort(reverse=True)  # 逆排序
print(f'num_list = {num_list}')
print('*' * 50)

# 删除
print('*' * 50)
stu_list.remove("lisi")  # 删除指定数据
stu_list.pop()  # 删除最后一个数据
stu_list.pop(2)  # 指定位置数据删除
stu_list.clear()  #清空列表
print('*' * 50)

# 元组
print('*' * 50)
stu_tuple = ("hyy", "hxx", 12, 13, 15, "16", "16", "hzz", 12)
print(stu_tuple)
print(stu_tuple.count("16"))
print(len(stu_tuple))

nums_tuple = ("hyy", "hzz", 12)
nums_str = "%s 是 %s 的 %d 倍数" % nums_tuple
print(nums_str)
print('*' * 50)

#字典
print('*' * 50)


def use_dict():
    stu_dict = {"name": "zhangsan"}
    print(stu_dict["name"])
    # print(stu_dict[stu]) # 若指定key不存在会报错
    stu_dict["age"] = 5  # 指定key不存在，则会创建
    stu_dict["name"] = "张三"  # 指定key存在，则会修改
    print('*' * 50)
    stu_dict.pop("name") # 删除
    print(len(stu_dict))  # 长度

    num_dict = {"number": "123",
                "egg": 5}
    stu_dict.update(num_dict) #合并
    # 3. 清空字典
    # stu_dict.clear()


def dictonary():
    my_dict = {"name" : "hyy", "age": "55", "email": "10086"}
    for x in my_dict:
        print(x)
    print('-' * 30)
    for x in my_dict.values():
        print(x)
    print('-' * 30)
    for x,y in my_dict.items():
        print(x, y)
    print('-' * 30)

    your_dict = {"name" : "hxx", "age": "44", "email": "10000"}, {"name" : "hzz", "age": "66", "email": "10010"}
    for x in your_dict:
        for y,z in x.items():
            print(y, z)
        print('-' * 30)


dictonary()

